import 'package:flutter/material.dart';
import 'package:flutter_mall_app/example/amap/amap_demo.dart';
import 'package:flutter_mall_app/example/jpush/jpush_demo.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'dart:ui' as ui show window;

class MemberCenter extends StatefulWidget {
  @override
  _MemberCenterState createState() => _MemberCenterState();
}

class _MemberCenterState extends State<MemberCenter> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("我的"),
        centerTitle: true,
      ),
      body: ListView(
        children: <Widget>[_buildHeader(), _buildOrderTitle(), _buildOrderType(), _buildBottom()],
      ),
    );
  }

  //用户信息区域
  Widget _buildHeader() {
    return Container(
      width: double.infinity,
      height: ScreenUtil().setHeight(350),
      padding: EdgeInsets.all(20),
      decoration: BoxDecoration(
          gradient:
              LinearGradient(colors: [Colors.blue, Colors.lightBlue, Colors.lightBlueAccent])),
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: 30),
            child: CircleAvatar(
              radius: 40,
              backgroundImage: CachedNetworkImageProvider(
                  "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556807129&di=716fde0e3502b6a6a74a7b5e2679ad4f&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.mp.itc.cn%2Fq_70%2Cc_zoom%2Cw_640%2Fupload%2F20170126%2F15a190c757cd4c1ba82d5edc80437fda_th.jpeg"),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 30),
            child: Text(
              "Jia Xin",
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic,
                  fontSize: ScreenUtil().setSp(35),
                  letterSpacing: 2.0,
                  color: Colors.white),
            ),
          ),
        ],
      ),
    );
  }

  //我的订单
  Widget _buildOrderTitle() {
    return Container(
      margin: EdgeInsets.only(top: 10),
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: ListTile(
        leading: Icon(Icons.format_list_bulleted),
        title: Text("我的订单"),
        trailing: Icon(Icons.arrow_forward),
      ),
    );
  }

  //订单区域
  Widget _buildOrderType() {
    return Container(
      margin: EdgeInsets.only(top: 10),
      height: ScreenUtil().setHeight(150),
      width: double.infinity,
      padding: EdgeInsets.only(top: 20),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Expanded(
            child: InkWell(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Icon(
                      Icons.payment,
                      size: 30,
                    ),
                    Text("AMap")
                  ],
                ),
              ),
              onTap: () {
               Navigator.of(context).push(MaterialPageRoute(builder: (context){
                 return AmapDemo();
               }));
              },
            ),
          ),
          Expanded(
            child: InkWell(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Icon(
                      Icons.query_builder,
                      size: 30,
                    ),
                    Text("待发货")
                  ],
                ),
              ),
              onTap: () {
                Navigator.of(context).push(MaterialPageRoute(builder: (context){
                  return JPushDemo();
                }));
              },
            ),
          ),
          Expanded(
            child: InkWell(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Icon(
                      Icons.local_shipping,
                      size: 30,
                    ),
                    Text("待收货")
                  ],
                ),
              ),
              onTap: () {},
            ),
          ),
          Expanded(
            child: InkWell(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Icon(
                      Icons.content_paste,
                      size: 30,
                    ),
                    Text("待评价")
                  ],
                ),
              ),
              onTap: () {},
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildBottom() {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(top: 10),
      child: Column(
        children: <Widget>[
          _buildMyListTile(Icon(Icons.bookmark_border), "领取优惠券"),
          _buildMyListTile(Icon(Icons.bookmark), "已领取优惠券"),
          _buildMyListTile(Icon(Icons.my_location), "地址管理"),
          _buildMyListTile(Icon(Icons.phone), "客服电话", subtitle: "0393-8800315"),
          _buildMyListTile(Icon(Icons.info), "关于商城"),
        ],
      ),
    );
  }

  Widget _buildMyListTile(Icon icon, String title, {String subtitle}) {
    return Container(
      width: double.infinity,
      color: Colors.white,
      margin: EdgeInsets.only(bottom: 1),
      child: ListTile(
        leading: icon,
        title: Text(title),
        trailing: Icon(Icons.arrow_forward),
        subtitle: subtitle == null ? null : Text("$subtitle"),
      ),
    );
  }
}
